import {
  queryGetApiGroupReq,
  queryGetDataApiDetailByIdReq,
  queryGetDataSourceListReq,
  queryGetParamsReq,
  queryGetTableFieldListReq,
  queryGetTableInfoListReq,
  queryLogReq,
  queryPreviewDataReq,
  querySaveGuideApiReq,
  querySaveScriptApiReq,
  queryTestGuideApiReq,
  queryTestScriptApiReq,
} from './api'

export default {
  namespace: 'myApiCreate',
  state: {},
  effects: {
    * queryGetDataSourceList({ params, cb }, { call, put }) {
      const res = yield call(queryGetDataSourceListReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetTableInfoList({ params, cb }, { call, put }) {
      const res = yield call(queryGetTableInfoListReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetTableFieldList({ params, cb }, { call, put }) {
      const res = yield call(queryGetTableFieldListReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryTestScriptApi({ params, cb }, { call, put }) {
      const res = yield call(queryTestScriptApiReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetApiGroup({ params, cb }, { call, put }) {
      const res = yield call(queryGetApiGroupReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryTestGuideApi({ params, cb }, { call, put }) {
      const res = yield call(queryTestGuideApiReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryLog({ params, cb }, { call, put }) {
      const res = yield call(queryLogReq, params)
      if (cb) {
        cb(res)
      }
    },
    * querySaveGuideApi({ params, cb }, { call, put }) {
      const res = yield call(querySaveGuideApiReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetParams({ params, cb }, { call, put }) {
      const res = yield call(queryGetParamsReq, params)
      if (cb) {
        cb(res)
      }
    },
    * querySaveScriptApi({ params, cb }, { call, put }) {
      const res = yield call(querySaveScriptApiReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryGetDataApiDetailById({ params, cb }, { call, put }) {
      const res = yield call(queryGetDataApiDetailByIdReq, params)
      if (cb) {
        cb(res)
      }
    },
    * queryPreviewData({ params, cb }, { call, put }) {
      const res = yield call(queryPreviewDataReq, params)
      if (cb) {
        cb(res)
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
  },
}
